﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Eniux.Framework.Infrastructure.Commands;
using Eniux.Framework.Infrastructure.core;
using Keys = System.Windows.Forms.Keys;

namespace HotKeyTest
{
    /// <summary>
    /// Window1.xaml 的交互逻辑
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            this.DataContext = this;
            Loaded += new RoutedEventHandler(Window1_Loaded);
            Closed += Window1_Closed;
        }

        private void Window1_Closed(object sender, EventArgs e)
        {
            // HotKeyManager.UnregisterHotKey(this);
        }

        private void Window1_Loaded(object sender, RoutedEventArgs e)
        {
            //HotKeyManager.RegisterHotKey(typeof(Window), "CTRL+E", this.CloseCommand);
            //HotKeyManager.RegisterHotKey(typeof(Window), new KeyGesture(Key.E, ModifierKeys.Control), CloseCommand);
            //HotKeyManager.RegisterHotKey(typeof(Window), ModifierKeys.Control, Key.D, this.CloseCommand);
        }

        #region Close Command

        private DelegateCommand _closeCommand = null;

        public DelegateCommand CloseCommand
        {
            get
            {
                if (this._closeCommand == null)
                {
                    this._closeCommand = new DelegateCommand(this.CloseExecute, this.CloseCanExecute);
                }

                return this._closeCommand;
            }
        }

        private bool CloseCanExecute()
        {
            return true;
        }

        private void CloseExecute()
        {
            this.Close();
        }

        #endregion Close Command
    }
}